image: node:latest

stages:
  - deploy
  - install

deploy:
  stage: deploy
  script:
    - echo "//<%= gitlab_host_without_port %>/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=<%= auth_token %>">.npmrc
    - npm publish
  only:
    - "<%= project.default_branch %>"
  tags:
    - "runner-for-<%= project.name %>"
install:
  stage: install
  script:
    - echo "//<%= gitlab_host_without_port %>/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=<%= auth_token %>">.npmrc
    - "npm config set @<%= registry_scope %>:registry <%= gitlab_address_without_port %>/api/v4/projects/${CI_PROJECT_ID}/packages/npm/"
    - "npm install <%= package.name %>"
  cache:
    key: ${CI_COMMIT_REF_NAME}
    paths:
      - node_modules/
  artifacts:
    paths:
      - node_modules/
  only:
    - "<%= project.default_branch %>"
  tags:
    - "runner-for-<%= project.name %>"